import pandas as pd
import numpy as np
from sklearn.datasets import load_wine
import matplotlib.pyplot as plt

wine = load_wine()

df_wine = pd.read_csv('./wine.data', header=None)  # 本地加载
X,y = df_wine.iloc[:,0:13].values,df_wine.iloc[:,13].values # 提取前13列作为特征列，取最后一列做为标签列
print(X,y)

# 绘制LDA图像
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA
lda = LDA(n_components=2)
X_lda = lda.fit(X,y).transform(X)

colors = ['r', 'g', 'b']
markers = ['s', 'x', 'o']
for c,i,m in zip(colors, np.unique(y), markers):
    plt.scatter(X_lda[y==i, 0], X_lda[y==i, 1], c=c, marker=m)
plt.xlabel("lda1")
plt.xlabel("lda2")
plt.title("LDA photo")
plt.legend(loc="lower left")
plt.show()
